#ifndef __FRAGMENT_APPLAYER_H__
#define __FRAGMENT_APPLAYER_H__

#include "stdint.h"

#include "Fragment_TransportLayer.h"

#define MAX_PARAM_LENGTH 64


typedef enum 
{
    OpCode_Read,
    OpCode_Write,
    OpCode_WriteWithoutResponse,
} OpCode_e;


typedef union {
    uint8_t value;
    struct {
        // RFU
        OpCode_e OpCode     : 2;

        // 0: this is a request pack, 1: this is a response pack
        uint8_t response    : 1; 
    } bitfield;
} OpFlag_u;


typedef struct AppLayerPacket {
    uint16_t message_id;  // id
    OpFlag_u op;
    uint16_t cmd;
    uint16_t param_length; // parameter length
    uint8_t param[MAX_PARAM_LENGTH]; // payload data
} AppLayerPacket_t;

// typedef struct ResponsePacket {
//     uint16_t message_id;  // id
//     OpFlag_u op;
//     uint16_t cmd;
//     uint16_t param_length; // parameter length
//     uint8_t param[MAX_PARAM_LENGTH]; // payload data
// } ResponsePacket_t;

#endif // _FRAGMENT_APPLAYER_H__